using System;
using Gtk;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;	 
using System.Data;
using Core;
using System.Collections.Generic;
using MongoDB.Driver.Linq;
using System.Configuration;
using MongoDBHelper;
using Topshelf;

namespace MonoAgent
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			//Application.Init ();
			//MainWindow win = new MainWindow ();
			//win.Show ();
			//Application.Run ();
			Context context1 = new Context("Key1","Value1");
			Context context2 = new Context("Key2","Value2");
			List<Context> contextlist = new List<Context>() ;
			contextlist.Add(context1);
			contextlist.Add(context2);
			
			
			
			ApplicationEvent appEvent = new ApplicationEvent("FirstEvent","Value",DateTime.Now.ToString(),contextlist);
			ApplicationEvent appEvent1 = new ApplicationEvent("Event2","Value2",DateTime.Now.AddSeconds(20).ToString(),contextlist);
			
			List<ApplicationEvent> appEventList = new List<ApplicationEvent>();
			appEventList.Add(appEvent);
			appEventList.Add(appEvent1);
			
			MongoDBAPI db = new MongoDBAPI(ConfigurationSettings.AppSettings["ServerName"],
			                                              ConfigurationSettings.AppSettings["DatabaseName"]);                      			
			
			db.SaveLogs(appEventList);
			db.SaveLogsPerSecond(appEventList);
		      
			
		
			
			
			// Code to Update
			//logEventsHourly.Update (
			//	//new QueryDocument {{"Text","FirstEvent" }},
			//	new QueryDocument {{"Hour",ts }},
			//	new UpdateDocument {{ "$set", new BsonDocument ("Count",2)  }}
			//	
			//	);
			
			// Code to Find			
			////MongoCollection coll =  logEventsHourly.Find(  "$Text" , "FirstEvent" );
			//BsonDocument firstHourlyEvent = logEventsHourly.FindOne ();
			//Console.WriteLine( firstHourlyEvent["Count"].AsInt32); 
			//Console.ReadLine();
			
			//Console.ReadLine();
			
			
            //HostFactory.Run(hostConfigurator =>
            //{
             // hostConfigurator.Service<MonoAgent.MonoAgentService>(
             //    serviceConfigurator =>
            //{
              //      serviceConfigurator.SetServiceName("MonoAgent");
                //    serviceConfigurator.ConstructUsing((name, coordinatorChannel) => new MonoAgent.MonoAgentService());
                  //  serviceConfigurator.WhenStarted(tc => tc.Start());
                    //serviceConfigurator.WhenStopped(tc => tc.Stop());
                //});

               // hostConfigurator.RunAsLocalSystem();
                //hostConfigurator.SetDescription("Read Queue");
                //hostConfigurator.SetDisplayName("Mono Agent");
                //hostConfigurator.SetServiceName("Topshelf Service");
            //});
        }
	}
}
